home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / emacs-complete / fsf / emacs / info / emacs-5 < prev    next >
Encoding:
GNU Info File  |  1994-10-06  |  44.4 KB  |  1,040 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3.  
  4. 
  5. File: emacs,  Node: Display Vars,  Prev: Optional Mode Line,  Up: Display
  6.  
  7. Variables Controlling Display
  8. =============================
  9.  
  10.    This section contains information for customization only.  Beginning
  11. users should skip it.
  12.  
  13.    The variable `mode-line-inverse-video' controls whether the mode
  14. line is displayed in inverse video (assuming the terminal supports it);
  15. `nil' means don't do so.  *Note Mode Line::.  If you specify the
  16. foreground color for the `mode-line' face, and
  17. `mode-line-inverse-video' is non-`nil', then the default background
  18. color for that face is the usual foreground color.  *Note Faces::.
  19.  
  20.    If the variable `inverse-video' is non-`nil', Emacs attempts to
  21. invert all the lines of the display from what they normally are.
  22.  
  23.    If the variable `visible-bell' is non-`nil', Emacs attempts to make
  24. the whole screen blink when it would normally make an audible bell
  25. sound.  This variable has no effect if your terminal does not have a way
  26. to make the screen blink.
  27.  
  28.    When you reenter Emacs after suspending, Emacs normally clears the
  29. screen and redraws the entire display.  On some terminals with more than
  30. one page of memory, it is possible to arrange the termcap entry so that
  31. the `ti' and `te' strings (output to the terminal when Emacs is entered
  32. and exited, respectively) switch between pages of memory so as to use
  33. one page for Emacs and another page for other output.  Then you might
  34. want to set the variable `no-redraw-on-reenter' non-`nil'; this tells
  35. Emacs to assume, when resumed, that the screen page it is using still
  36. contains what Emacs last wrote there.
  37.  
  38.    The variable `echo-keystrokes' controls the echoing of
  39. multi-character keys; its value is the number of seconds of pause
  40. required to cause echoing to start, or zero meaning don't echo at all.
  41. *Note Echo Area::.
  42.  
  43.    If the variable `ctl-arrow' is `nil', control characters in the
  44. buffer are displayed with octal escape sequences, all except newline
  45. and tab.  Altering the value of `ctl-arrow' makes it local to the
  46. current buffer; until that time, the default value is in effect.  The
  47. default is initially `t'.  *Note Display Tables: (elisp)Display Tables.
  48.  
  49.    Normally, a tab character in the buffer is displayed as whitespace
  50. which extends to the next display tab stop position, and display tab
  51. stops come at intervals equal to eight spaces.  The number of spaces
  52. per tab is controlled by the variable `tab-width', which is made local
  53. by changing it, just like `ctl-arrow'.  Note that how the tab character
  54. in the buffer is displayed has nothing to do with the definition of TAB
  55. as a command.  The variable `tab-width' must have an integer value
  56. between 1 and 1000, inclusive.
  57.  
  58.    If you set the variable `selective-display-ellipses' to `nil', the
  59. three dots do not appear at the end of a line that precedes invisible
  60. lines.  Then there is no visible indication of the invisible lines.
  61. This variable too becomes local automatically when set.
  62.  
  63.    If the variable `truncate-lines' is non-`nil', then each line of
  64. text gets just one screen line for display; if the text line is too
  65. long, display shows only the part that fits.  If `truncate-lines' is
  66. `nil', then long text lines display as more than one screen line,
  67. enough to show the whole text of the line.  *Note Continuation Lines::.
  68. Altering the value of `truncate-lines' makes it local to the current
  69. buffer; until that time, the default value is in effect.  The default
  70. is initially `nil'.
  71.  
  72.    If the variable `truncate-partial-width-windows' is non-`nil', it
  73. forces truncation rather than continuation in any window less than the
  74. full width of the screen or frame, regardless of the value of
  75. `truncate-lines'.  For information about side-by-side windows, see
  76. *Note Split Window::.  See also *Note Display: (elisp)Display.
  77.  
  78.    The variable `baud-rate' holds the the output speed of the terminal,
  79. as far as Emacs knows.  Setting this variable does not change the speed
  80. of actual data transmission, but the value is used for calculations
  81. such as padding.  It also affects decisions about whether to scroll
  82. part of the screen or redraw it instead--even when using a window
  83. system.  (We designed it this way, despite the fact that a window
  84. system has no true "output speed", to give you a way to tune these
  85. decisions.)
  86.  
  87. 
  88. File: emacs,  Node: Search,  Next: Fixit,  Prev: Display,  Up: Top
  89.  
  90. Searching and Replacement
  91. *************************
  92.  
  93.    Like other editors, Emacs has commands for searching for occurrences
  94. of a string.  The principal search command is unusual in that it is
  95. "incremental"; it begins to search before you have finished typing the
  96. search string.  There are also nonincremental search commands more like
  97. those of other editors.
  98.  
  99.    Besides the usual `replace-string' command that finds all
  100. occurrences of one string and replaces them with another, Emacs has a
  101. fancy replacement command called `query-replace' which asks
  102. interactively which occurrences to replace.
  103.  
  104. * Menu:
  105.  
  106. * Incremental Search::       Search happens as you type the string.
  107. * Nonincremental Search::  Specify entire string and then search.
  108. * Word Search::           Search for sequence of words.
  109. * Regexp Search::       Search for match for a regexp.
  110. * Regexps::           Syntax of regular expressions.
  111. * Search Case::           To ignore case while searching, or not.
  112. * Replace::           Search, and replace some or all matches.
  113. * Other Repeating Search:: Operating on all matches for some regexp.
  114.  
  115. 
  116. File: emacs,  Node: Incremental Search,  Next: Nonincremental Search,  Prev: Search,  Up: Search
  117.  
  118. Incremental Search
  119. ==================
  120.  
  121.    An incremental search begins searching as soon as you type the first
  122. character of the search string.  As you type in the search string, Emacs
  123. shows you where the string (as you have typed it so far) would be
  124. found.  When you have typed enough characters to identify the place you
  125. want, you can stop.  Depending on what you plan to do next, you may or
  126. may not need to terminate the search explicitly with RET.
  127.  
  128. `C-s'
  129.      Incremental search forward (`isearch-forward').
  130.  
  131. `C-r'
  132.      Incremental search backward (`isearch-backward').
  133.  
  134.    `C-s' starts an incremental search.  `C-s' reads characters from the
  135. keyboard and positions the cursor at the first occurrence of the
  136. characters that you have typed.  If you type `C-s' and then `F', the
  137. cursor moves right after the first `F'.  Type an `O', and see the
  138. cursor move to after the first `FO'.  After another `O', the cursor is
  139. after the first `FOO' after the place where you started the search.
  140. Meanwhile, the search string `FOO' has been echoed in the echo area.
  141.  
  142.    If you make a mistake in typing the search string, you can cancel
  143. characters with DEL.  Each DEL cancels the last character of search
  144. string.  This does not happen until Emacs is ready to read another
  145. input character; first it must either find, or fail to find, the
  146. character you want to erase.  If you do not want to wait for this to
  147. happen, use `C-g' as described below.
  148.  
  149.    When you are satisfied with the place you have reached, you can type
  150. RET, which stops searching, leaving the cursor where the search brought
  151. it.  Also, any command not specially meaningful in searches stops the
  152. searching and is then executed.  Thus, typing `C-a' would exit the
  153. search and then move to the beginning of the line.  RET is necessary
  154. only if the next command you want to type is a printing character, DEL,
  155. RET, or another control character that is special within searches
  156. (`C-q', `C-w', `C-r', `C-s', `C-y', `M-y', `M-r', or `M-s').
  157.  
  158.    Sometimes you search for `FOO' and find it, but not the one you
  159. expected to find.  There was a second `FOO' that you forgot about,
  160. before the one you were looking for.  In this event, type another `C-s'
  161. to move to the next occurrence of the search string.  This can be done
  162. any number of times.  If you overshoot, you can cancel some `C-s'
  163. characters with DEL.
  164.  
  165.    After you exit a search, you can search for the same string again by
  166. typing just `C-s C-s': the first `C-s' is the key that invokes
  167. incremental search, and the second `C-s' means "search again".
  168.  
  169.    To reuse earlier search strings, use the "search ring".  The
  170. commands `M-p' and `M-n' move through the ring to pick a search string
  171. to reuse.  These commands leave the selected search ring element in the
  172. minibuffer, where you can edit it.  Type `C-s' or `C-r' to terminate
  173. editing the string and search for it.
  174.  
  175.    If your string is not found at all, the echo area says `Failing
  176. I-Search'.  The cursor is after the place where Emacs found as much of
  177. your string as it could.  Thus, if you search for `FOOT', and there is
  178. no `FOOT', you might see the cursor after the `FOO' in `FOOL'.  At this
  179. point there are several things you can do.  If your string was
  180. mistyped, you can rub some of it out and correct it.  If you like the
  181. place you have found, you can type RET or some other Emacs command to
  182. "accept what the search offered".  Or you can type `C-g', which removes
  183. from the search string the characters that could not be found (the `T'
  184. in `FOOT'), leaving those that were found (the `FOO' in `FOOT').  A
  185. second `C-g' at that point cancels the search entirely, returning point
  186. to where it was when the search started.
  187.  
  188.    An upper-case letter in the search string makes the search
  189. case-sensitive.  If you delete the upper-case character from the search
  190. string, it ceases to have this effect.  *Note Search Case::.
  191.  
  192.    If a search is failing and you ask to repeat it by typing another
  193. `C-s', it starts again from the beginning of the buffer.  Repeating a
  194. failing reverse search with `C-r' starts again from the end.  This is
  195. called "wrapping around".  `Wrapped' appears in the search prompt once
  196. this has happened.
  197.  
  198.    The `C-g' "quit" character does special things during searches; just
  199. what it does depends on the status of the search.  If the search has
  200. found what you specified and is waiting for input, `C-g' cancels the
  201. entire search.  The cursor moves back to where you started the search.
  202. If `C-g' is typed when there are characters in the search string that
  203. have not been found--because Emacs is still searching for them, or
  204. because it has failed to find them--then the search string characters
  205. which have not been found are discarded from the search string.  With
  206. them gone, the search is now successful and waiting for more input, so
  207. a second `C-g' will cancel the entire search.
  208.  
  209.    To search for a newline, type LFD (also known as `C-j').  To search
  210. for another control character such as control-S or carriage return, you
  211. must quote it by typing `C-q' first.  This function of `C-q' is
  212. analogous to its meaning as an Emacs command: it causes the following
  213. character to be treated the way a graphic character would normally be
  214. treated in the same context.  You can also specify a character by its
  215. octal code: enter `C-q' followed by three octal digits.
  216.  
  217.    You can change to searching backwards with `C-r'.  If a search fails
  218. because the place you started was too late in the file, you should do
  219. this.  Repeated `C-r' keeps looking for more occurrences backwards.  A
  220. `C-s' starts going forwards again.  `C-r' in a search can be canceled
  221. with DEL.
  222.  
  223.    If you know initially that you want to search backwards, you can use
  224. `C-r' instead of `C-s' to start the search, because `C-r' as a key runs
  225. a command (`isearch-backward') to search backward.
  226.  
  227.    The characters `C-y' and `C-w' can be used in incremental search to
  228. grab text from the buffer into the search string.  This makes it
  229. convenient to search for another occurrence of text at point.  `C-w'
  230. copies the word after point as part of the search string, advancing
  231. point over that word.  Another `C-s' to repeat the search will then
  232. search for a string including that word.  `C-y' is similar to `C-w' but
  233. copies all the rest of the current line into the search string.  Both
  234. `C-y' and `C-w' convert the text they copy to lower case if the search
  235. is current not case-sensitive; this is so the search remains
  236. case-insensitive.
  237.  
  238.    The character `M-y' copies text from the kill ring into the search
  239. string.  It uses the same text that `C-y' as a command would yank.
  240. *Note Yanking::.
  241.  
  242.    To customize the special characters that incremental search
  243. understands, alter their bindings in the keymap `isearch-mode-map'.
  244.  
  245. Slow Terminal Incremental Search
  246. --------------------------------
  247.  
  248.    Incremental search on a slow terminal uses a modified style of
  249. display that is designed to take less time.  Instead of redisplaying
  250. the buffer at each place the search gets to, it creates a new
  251. single-line window and uses that to display the line that the search
  252. has found.  The single-line window comes into play as soon as point
  253. gets outside of the text that is already on the screen.
  254.  
  255.    When you terminate the search, the single-line window is removed.
  256. Then Emacs redisplays the window in which the search was done, to show
  257. its new position of point.
  258.  
  259.    The slow terminal style of display is used when the terminal baud
  260. rate is less than or equal to the value of the variable
  261. `search-slow-speed', initially 1200.
  262.  
  263.    The number of lines to use in slow terminal search display is
  264. controlled by the variable `search-slow-window-lines'.  1 is its normal
  265. value.
  266.  
  267. 
  268. File: emacs,  Node: Nonincremental Search,  Next: Word Search,  Prev: Incremental Search,  Up: Search
  269.  
  270. Nonincremental Search
  271. =====================
  272.  
  273.    Emacs also has conventional nonincremental search commands, which
  274. require you to type the entire search string before searching begins.
  275.  
  276. `C-s RET STRING RET'
  277.      Search for STRING.
  278.  
  279. `C-r RET STRING RET'
  280.      Search backward for STRING.
  281.  
  282.    To do a nonincremental search, first type `C-s RET'.  This enters
  283. the minibuffer to read the search string; terminate the string with
  284. RET, and then the search takes place.  If the string is not found, the
  285. search command gets an error.
  286.  
  287.    The way `C-s RET' works is that the `C-s' invokes incremental
  288. search, which is specially programmed to invoke nonincremental search
  289. if the argument you give it is empty.  (Such an empty argument would
  290. otherwise be useless.)  `C-r RET' also works this way.
  291.  
  292.    However, nonincremental searches performed using `C-s RET' do not
  293. call `search-forward' right away.  The first thing done is to see if
  294. the next character is `C-w', which requests a word search.  *Note Word
  295. Search::.
  296.  
  297.    Forward and backward nonincremental searches are implemented by the
  298. commands `search-forward' and `search-backward'.  These commands may be
  299. bound to keys in the usual manner.  The feature that you can get to
  300. them via the incremental search commands exists for historical reasons,
  301. and to avoid the need to find suitable key sequences for them.
  302.  
  303. 
  304. File: emacs,  Node: Word Search,  Next: Regexp Search,  Prev: Nonincremental Search,  Up: Search
  305.  
  306. Word Search
  307. ===========
  308.  
  309.    Word search searches for a sequence of words without regard to how
  310. the words are separated.  More precisely, you type a string of many
  311. words, using single spaces to separate them, and the string can be
  312. found even if there are multiple spaces, newlines or other punctuation
  313. between the words.
  314.  
  315.    Word search is useful for editing a printed document made with a text
  316. formatter.  If you edit while looking at the printed, formatted version,
  317. you can't tell where the line breaks are in the source file.  With word
  318. search, you can search without having to know them.
  319.  
  320. `C-s RET C-w WORDS RET'
  321.      Search for WORDS, ignoring details of punctuation.
  322.  
  323. `C-r RET C-w WORDS RET'
  324.      Search backward for WORDS, ignoring details of punctuation.
  325.  
  326.    Word search is a special case of nonincremental search and is invoked
  327. with `C-s RET C-w'.  This is followed by the search string, which must
  328. always be terminated with RET.  Being nonincremental, this search does
  329. not start until the argument is terminated.  It works by constructing a
  330. regular expression and searching for that; see *Note Regexp Search::.
  331.  
  332.    Use `C-r RET C-w' to do backward word search.
  333.  
  334.    Forward and backward word searches are implemented by the commands
  335. `word-search-forward' and `word-search-backward'.  These commands may
  336. be bound to keys in the usual manner.  The feature that you can get to
  337. them via the incremental search commands exists for historical reasons,
  338. and to avoid the need to find suitable key sequences for them.
  339.  
  340. 
  341. File: emacs,  Node: Regexp Search,  Next: Regexps,  Prev: Word Search,  Up: Search
  342.  
  343. Regular Expression Search
  344. =========================
  345.  
  346.    A "regular expression" ("regexp", for short) is a pattern that
  347. denotes a class of alternative strings to match, possibly infinitely
  348. many.  In GNU Emacs, you can search for the next match for a regexp
  349. either incrementally or not.
  350.  
  351.    Incremental search for a regexp is done by typing `C-M-s'
  352. (`isearch-forward-regexp').  This command reads a search string
  353. incrementally just like `C-s', but it treats the search string as a
  354. regexp rather than looking for an exact match against the text in the
  355. buffer.  Each time you add text to the search string, you make the
  356. regexp longer, and the new regexp is searched for.  To search backward
  357. in the buffer, use `C-M-r' (`isearch-backward-regexp').
  358.  
  359.    All of the control characters that do special things within an
  360. ordinary incremental search have the same function in incremental regexp
  361. search.  Typing `C-s' or `C-r' immediately after starting the search
  362. retrieves the last incremental search regexp used; that is to say,
  363. incremental regexp and non-regexp searches have independent defaults.
  364. They also have separate search rings that you can access with `M-p' and
  365. `M-n'.
  366.  
  367.    If you type SPC in incremental regexp search, it matches any
  368. sequence of whitespace characters, including newlines.  If you want to
  369. match just a space, type `C-q SPC'.
  370.  
  371.    Note that adding characters to the regexp in an incremental regexp
  372. search can make the cursor move back and start again.  For example, if
  373. you have searched for `foo' and you add `\|bar', the cursor backs up in
  374. case the first `bar' precedes the first `foo'.
  375.  
  376.    Nonincremental search for a regexp is done by the functions
  377. `re-search-forward' and `re-search-backward'.  You can invoke these
  378. with `M-x', or bind them to keys, or invoke them by way of incremental
  379. regexp search with `C-M-s RET' and `C-M-r RET'.
  380.  
  381. 
  382. File: emacs,  Node: Regexps,  Next: Search Case,  Prev: Regexp Search,  Up: Search
  383.  
  384. Syntax of Regular Expressions
  385. =============================
  386.  
  387.    Regular expressions have a syntax in which a few characters are
  388. special constructs and the rest are "ordinary".  An ordinary character
  389. is a simple regular expression which matches that same character and
  390. nothing else.  The special characters are `$', `^', `.', `*', `+', `?',
  391. `[', `]' and `\'.  Any other character appearing in a regular
  392. expression is ordinary, unless a `\' precedes it.
  393.  
  394.    For example, `f' is not a special character, so it is ordinary, and
  395. therefore `f' is a regular expression that matches the string `f' and
  396. no other string.  (It does *not* match the string `ff'.)  Likewise, `o'
  397. is a regular expression that matches only `o'.  (When case distinctions
  398. are being ignored, these regexps also match `F' and `O', but we
  399. consider this a generalization of "the same string", rather than an
  400. exception.)
  401.  
  402.    Any two regular expressions A and B can be concatenated.  The result
  403. is a regular expression which matches a string if A matches some amount
  404. of the beginning of that string and B matches the rest of the string.
  405.  
  406.    As a simple example, we can concatenate the regular expressions `f'
  407. and `o' to get the regular expression `fo', which matches only the
  408. string `fo'.  Still trivial.  To do something nontrivial, you need to
  409. use one of the special characters.  Here is a list of them.
  410.  
  411. `. (Period)'
  412.      is a special character that matches any single character except a
  413.      newline.  Using concatenation, we can make regular expressions
  414.      like `a.b' which matches any three-character string which begins
  415.      with `a' and ends with `b'.
  416.  
  417. `*'
  418.      is not a construct by itself; it is a postfix operator, which
  419.      means to match the preceding regular expression repetitively as
  420.      many times as possible.  Thus, `o*' matches any number of `o's
  421.      (including no `o's).
  422.  
  423.      `*' always applies to the *smallest* possible preceding
  424.      expression.  Thus, `fo*' has a repeating `o', not a repeating
  425.      `fo'.  It matches `f', `fo', `foo', and so on.
  426.  
  427.      The matcher processes a `*' construct by matching, immediately, as
  428.      many repetitions as can be found.  Then it continues with the rest
  429.      of the pattern.  If that fails, backtracking occurs, discarding
  430.      some of the matches of the `*'-modified construct in case that
  431.      makes it possible to match the rest of the pattern.  For example,
  432.      matching `ca*ar' against the string `caaar', the `a*' first tries
  433.      to match all three `a's; but the rest of the pattern is `ar' and
  434.      there is only `r' left to match, so this try fails.  The next
  435.      alternative is for `a*' to match only two `a's.  With this choice,
  436.      the rest of the regexp matches successfully.
  437.  
  438. `+'
  439.      is a postfix character, similar to `*' except that it must match
  440.      the preceding expression at least once.  So, for example, `ca+r'
  441.      matches the strings `car' and `caaaar' but not the string `cr',
  442.      whereas `ca*r' matches all three strings.
  443.  
  444. `?'
  445.      is a postfix character, similar to `*' except that it can match the
  446.      preceding expression either once or not at all.  For example,
  447.      `ca?r' matches `car' or `cr'; nothing else.
  448.  
  449. `[ ... ]'
  450.      is a "character set", which begins with `[' and is terminated by
  451.      `]'.  In the simplest case, the characters between the two
  452.      brackets are what this set can match.
  453.  
  454.      Thus, `[ad]' matches either one `a' or one `d', and `[ad]*'
  455.      matches any string composed of just `a's and `d's (including the
  456.      empty string), from which it follows that `c[ad]*r' matches `cr',
  457.      `car', `cdr', `caddaar', etc.
  458.  
  459.      You can also include character ranges a character set, by writing
  460.      two characters with a `-' between them.  Thus, `[a-z]' matches any
  461.      lower-case letter.  Ranges may be intermixed freely with individual
  462.      characters, as in `[a-z$%.]', which matches any lower case letter
  463.      or `$', `%' or period.
  464.  
  465.      Note that the usual regexp special characters are not special
  466.      inside a character set.  A completely different set of special
  467.      characters exists inside character sets: `]', `-' and `^'.
  468.  
  469.      To include a `]' in a character set, you must make it the first
  470.      character.  For example, `[]a]' matches `]' or `a'.  To include a
  471.      `-', write `-' as the first or last character of the set, or put
  472.      it after a range.  Thus, `[]-]' matches both `]' and `-'.
  473.  
  474.      To include `^', make it other than the first character in the set.
  475.  
  476. `[^ ... ]'
  477.      `[^' begins a "complemented character set", which matches any
  478.      character except the ones specified.  Thus, `[^a-z0-9A-Z]' matches
  479.      all characters *except* letters and digits.
  480.  
  481.      `^' is not special in a character set unless it is the first
  482.      character.  The character following the `^' is treated as if it
  483.      were first (`-' and `]' are not special there).
  484.  
  485.      A complemented character set can match a newline, unless newline is
  486.      mentioned as one of the characters not to match.  This is in
  487.      contrast to the handling of regexps in programs such as `grep'.
  488.  
  489. `^'
  490.      is a special character that matches the empty string, but only at
  491.      the beginning of a line in the text being matched.  Otherwise it
  492.      fails to match anything.  Thus, `^foo' matches a `foo' which
  493.      occurs at the beginning of a line.
  494.  
  495. `$'
  496.      is similar to `^' but matches only at the end of a line.  Thus,
  497.      `xx*$' matches a string of one `x' or more at the end of a line.
  498.  
  499. `\'
  500.      has two functions: it quotes the special characters (including
  501.      `\'), and it introduces additional special constructs.
  502.  
  503.      Because `\' quotes special characters, `\$' is a regular
  504.      expression which matches only `$', and `\[' is a regular
  505.      expression which matches only `[', etc.
  506.  
  507.    Note: for historical compatibility, special characters are treated as
  508. ordinary ones if they are in contexts where their special meanings make
  509. no sense.  For example, `*foo' treats `*' as ordinary since there is no
  510. preceding expression on which the `*' can act.  It is poor practice to
  511. depend on this behavior; better to quote the special character anyway,
  512. regardless of where is appears.
  513.  
  514.    For the most part, `\' followed by any character matches only that
  515. character.  However, there are several exceptions: two-character
  516. sequences starting with `\' which have special meanings.  The second
  517. character in the sequence is always an ordinary character on their own.
  518. Here is a table of `\' constructs.
  519.  
  520. `\|'
  521.      specifies an alternative.  Two regular expressions A and B with
  522.      `\|' in between form an expression that matches anything that
  523.      either A or B matches.
  524.  
  525.      Thus, `foo\|bar' matches either `foo' or `bar' but no other string.
  526.  
  527.      `\|' applies to the largest possible surrounding expressions.
  528.      Only a surrounding `\( ... \)' grouping can limit the scope of
  529.      `\|'.
  530.  
  531.      Full backtracking capability exists to handle multiple uses of
  532.      `\|'.
  533.  
  534. `\( ... \)'
  535.      is a grouping construct that serves three purposes:
  536.  
  537.        1. To enclose a set of `\|' alternatives for other operations.
  538.           Thus, `\(foo\|bar\)x' matches either `foox' or `barx'.
  539.  
  540.        2. To enclose a complicated expression for the postfix operators
  541.           `*', `+' and `?' to operate on.  Thus, `ba\(na\)*' matches
  542.           `bananana', etc., with any (zero or more) number of `na'
  543.           strings.
  544.  
  545.        3. To mark a matched substring for future reference.
  546.  
  547.      This last application is not a consequence of the idea of a
  548.      parenthetical grouping; it is a separate feature which is assigned
  549.      as a second meaning to the same `\( ... \)' construct.  In practice
  550.      there is no conflict between the two meanings.  Here is an
  551.      explanation of this feature:
  552.  
  553. `\D'
  554.      after the end of a `\( ... \)' construct, the matcher remembers
  555.      the beginning and end of the text matched by that construct.  Then,
  556.      later on in the regular expression, you can use `\' followed by the
  557.      digit D to mean "match the same text matched the Dth time by the
  558.      `\( ... \)' construct."
  559.  
  560.      The strings matching the first nine `\( ... \)' constructs
  561.      appearing in a regular expression are assigned numbers 1 through 9
  562.      in order that the open-parentheses appear in the regular
  563.      expression.  `\1' through `\9' refer to the text previously
  564.      matched by the corresponding `\( ... \)' construct.
  565.  
  566.      For example, `\(.*\)\1' matches any newline-free string that is
  567.      composed of two identical halves.  The `\(.*\)' matches the first
  568.      half, which may be anything, but the `\1' that follows must match
  569.      the same exact text.
  570.  
  571.      If a particular `\( ... \)' construct matches more than once
  572.      (which can easily happen if it is followed by `*'), only the last
  573.      match is recorded.
  574.  
  575. `\`'
  576.      matches the empty string, provided it is at the beginning of the
  577.      buffer.
  578.  
  579. `\''
  580.      matches the empty string, provided it is at the end of the buffer.
  581.  
  582. `\b'
  583.      matches the empty string, provided it is at the beginning or end
  584.      of a word.  Thus, `\bfoo\b' matches any occurrence of `foo' as a
  585.      separate word.  `\bballs?\b' matches `ball' or `balls' as a
  586.      separate word.
  587.  
  588. `\B'
  589.      matches the empty string, provided it is *not* at the beginning or
  590.      end of a word.
  591.  
  592. `\<'
  593.      matches the empty string, provided it is at the beginning of a
  594.      word.
  595.  
  596. `\>'
  597.      matches the empty string, provided it is at the end of a word.
  598.  
  599. `\w'
  600.      matches any word-constituent character.  The syntax table
  601.      determines which characters these are.  *Note Syntax::.
  602.  
  603. `\W'
  604.      matches any character that is not a word-constituent.
  605.  
  606. `\sC'
  607.      matches any character whose syntax is C.  Here C is a character
  608.      which represents a syntax code: thus, `w' for word constituent,
  609.      `(' for open-parenthesis, etc.  Represent a character of
  610.      whitespace (which can be a newline) by either `-' or a space
  611.      character.
  612.  
  613. `\SC'
  614.      matches any character whose syntax is not C.
  615.  
  616.    The constructs that pertain to words and syntax are controlled by the
  617. setting of the syntax table (*note Syntax::.).
  618.  
  619.    Here is a complicated regexp, used by Emacs to recognize the end of a
  620. sentence together with any whitespace that follows.  It is given in Lisp
  621. syntax to enable you to distinguish the spaces from the tab characters.
  622. In Lisp syntax, the string constant begins and ends with a
  623. double-quote.  `\"' stands for a double-quote as part of the regexp,
  624. `\\' for a backslash as part of the regexp, `\t' for a tab and `\n' for
  625. a newline.
  626.  
  627.      "[.?!][]\"')]*\\($\\|\t\\|  \\)[ \t\n]*"
  628.  
  629. This contains four parts in succession: a character set matching period,
  630. `?', or `!'; a character set matching close-brackets, quotes, or
  631. parentheses, repeated any number of times; an alternative in
  632. backslash-parentheses that matches end-of-line, a tab, or two spaces;
  633. and a character set matching whitespace characters, repeated any number
  634. of times.
  635.  
  636.    To enter the same regexp interactively, you would type TAB to enter
  637. a tab, and `C-q C-j' to enter a newline.  You would also type single
  638. slashes as themselves, instead of doubling them for Lisp syntax.
  639.  
  640. 
  641. File: emacs,  Node: Search Case,  Next: Replace,  Prev: Regexps,  Up: Search
  642.  
  643. Searching and Case
  644. ==================
  645.  
  646.    Incremental searches in Emacs normally ignore the case of the text
  647. they are searching through, if you specify the text in lower case.
  648. Thus, if you specify searching for `foo', then `Foo' and `foo' are also
  649. considered a match.  Regexps, and in particular character sets, are
  650. included: `[ab]' would match `a' or `A' or `b' or `B'.
  651.  
  652.    An upper-case letter in the incremental search string makes the
  653. search case-sensitive.  Thus, searching for `Foo' does not find `foo'
  654. or `FOO'.  This applies to regular expression search as well as to
  655. string search.  The effect ceases if you delete the upper-case letter
  656. from the search string.
  657.  
  658.    If you set the variable `case-fold-search' to `nil', then all
  659. letters must match exactly, including case.  This is a per-buffer
  660. variable; altering the variable affects only the current buffer, but
  661. there is a default value which you can change as well.  *Note Locals::.
  662. This variable applies to nonincremental searches also, including those
  663. performed by the replace commands (*note Replace::.).
  664.  
  665. 
  666. File: emacs,  Node: Replace,  Next: Other Repeating Search,  Prev: Search Case,  Up: Search
  667.  
  668. Replacement Commands
  669. ====================
  670.  
  671.    Global search-and-replace operations are not needed as often in Emacs
  672. as they are in other editors(1), but they are available.  In addition
  673. to the simple `M-x replace-string' command which is like that found in
  674. most editors, there is a `M-x query-replace' command which asks you, for
  675. each occurrence of the pattern, whether to replace it.
  676.  
  677.    The replace commands all replace one string (or regexp) with one
  678. replacement string.  It is possible to perform several replacements in
  679. parallel using the command `expand-region-abbrevs'.  *Note Expanding
  680. Abbrevs::.
  681.  
  682. * Menu:
  683.  
  684. * Unconditional Replace::  Replacing all matches for a string.
  685. * Regexp Replace::         Replacing all matches for a regexp.
  686. * Replacement and Case::   How replacements preserve case of letters.
  687. * Query Replace::          How to use querying.
  688.  
  689.    ---------- Footnotes ----------
  690.  
  691.    (1)  In some editors, search-and-replace operations are the only
  692. convenient way to make a single change in the text.
  693.  
  694. 
  695. File: emacs,  Node: Unconditional Replace,  Next: Regexp Replace,  Prev: Replace,  Up: Replace
  696.  
  697. Unconditional Replacement
  698. -------------------------
  699.  
  700. `M-x replace-string RET STRING RET NEWSTRING RET'
  701.      Replace every occurrence of STRING with NEWSTRING.
  702.  
  703. `M-x replace-regexp RET REGEXP RET NEWSTRING RET'
  704.      Replace every match for REGEXP with NEWSTRING.
  705.  
  706.    To replace every instance of `foo' after point with `bar', use the
  707. command `M-x replace-string' with the two arguments `foo' and `bar'.
  708. Replacement happens only in the text after point, so if you want to
  709. cover the whole buffer you must go to the beginning first.  All
  710. occurrences up to the end of the buffer are replaced; to limit
  711. replacement to part of the buffer, narrow to that part of the buffer
  712. before doing the replacement (*note Narrowing::.).
  713.  
  714.    When `replace-string' exits, point is left at the last occurrence
  715. replaced.  The position of point where the `replace-string' command was
  716. issued is remembered on the mark ring; use `C-u C-SPC' to move back
  717. there.
  718.  
  719.    A numeric argument restricts replacement to matches that are
  720. surrounded by word boundaries.  The argument's value doesn't matter.
  721.  
  722. 
  723. File: emacs,  Node: Regexp Replace,  Next: Replacement and Case,  Prev: Unconditional Replace,  Up: Replace
  724.  
  725. Regexp Replacement
  726. ------------------
  727.  
  728.    The `M-x replace-string' command replaces exact matches for a single
  729. string.  The similar command `M-x replace-regexp' replaces any match
  730. for a specified pattern.
  731.  
  732.    In `replace-regexp', the NEWSTRING need not be constant: it can
  733. refer to all or part of what is matched by the REGEXP.  `\&' in
  734. NEWSTRING stands for the entire match being replaced.  `\D' in
  735. NEWSTRING, where D is a digit, stands for whatever matched the Dth
  736. parenthesized grouping in REGEXP.  To include a `\' in the text to
  737. replace with, you must enter `\\'.  For example,
  738.  
  739.      M-x replace-regexp RET c[ad]+r RET \&-safe RET
  740.  
  741. replaces (for example) `cadr' with `cadr-safe' and `cddr' with
  742. `cddr-safe'.
  743.  
  744.      M-x replace-regexp RET \(c[ad]+r\)-safe RET \1 RET
  745.  
  746. performs the inverse transformation.
  747.  
  748. 
  749. File: emacs,  Node: Replacement and Case,  Next: Query Replace,  Prev: Regexp Replace,  Up: Replace
  750.  
  751. Replace Commands and Case
  752. -------------------------
  753.  
  754.    If the arguments to a replace command are in lower case, it preserves
  755. case when it makes a replacement.  Thus, the command
  756.  
  757.      M-x replace-string RET foo RET bar RET
  758.  
  759. replaces a lower case `foo' with a lower case `bar', `FOO' with `BAR',
  760. and `Foo' with `Bar'.  If upper case letters are used in the second
  761. argument, they remain upper case every time that argument is inserted.
  762. If upper case letters are used in the first argument, the second
  763. argument is always substituted exactly as given, with no case
  764. conversion.  Likewise, if the variable `case-replace' is set to `nil',
  765. replacement is done without case conversion.  If `case-fold-search' is
  766. set to `nil', case is significant in matching occurrences of `foo' to
  767. replace; this also inhibits case conversion of the replacement string.
  768.  
  769. 
  770. File: emacs,  Node: Query Replace,  Prev: Replacement and Case,  Up: Replace
  771.  
  772. Query Replace
  773. -------------
  774.  
  775. `M-% STRING RET NEWSTRING RET'
  776. `M-x query-replace RET STRING RET NEWSTRING RET'
  777.      Replace some occurrences of STRING with NEWSTRING.
  778.  
  779. `M-x query-replace-regexp RET REGEXP RET NEWSTRING RET'
  780.      Replace some matches for REGEXP with NEWSTRING.
  781.  
  782.    If you want to change only some of the occurrences of `foo' to
  783. `bar', not all of them, then you cannot use an ordinary
  784. `replace-string'.  Instead, use `M-%' (`query-replace').  This command
  785. finds occurrences of `foo' one by one, displays each occurrence and
  786. asks you whether to replace it.  A numeric argument to `query-replace'
  787. tells it to consider only occurrences that are bounded by
  788. word-delimiter characters.  This preserves case, just like
  789. `replace-string', provided `case-replace' is non-`nil', as it normally
  790. is.
  791.  
  792.    Aside from querying, `query-replace' works just like
  793. `replace-string', and `query-replace-regexp' works just like
  794. `replace-regexp'.  The shortest way to type this command name is `M-x
  795. que SPC SPC SPC RET'.
  796.  
  797.    The things you can type when you are shown an occurrence of STRING
  798. or a match for REGEXP are:
  799.  
  800. `SPC'
  801.      to replace the occurrence with NEWSTRING.
  802.  
  803. `DEL'
  804.      to skip to the next occurrence without replacing this one.
  805.  
  806. `, (Comma)'
  807.      to replace this occurrence and display the result.  You are then
  808.      asked for another input character to say what to do next.  Since
  809.      the replacement has already been made, DEL and SPC are equivalent
  810.      in this situation; both move to the next occurrence.
  811.  
  812.      You could type `C-r' at this point (see below) to alter the
  813.      replaced text.  You could also type `C-x u' to undo the
  814.      replacement; this exits the `query-replace', so if you want to do
  815.      further replacement you must use `C-x ESC ESC RET' to restart
  816.      (*note Repetition::.).
  817.  
  818. `RET'
  819.      to exit without doing any more replacements.
  820.  
  821. `. (Period)'
  822.      to replace this occurrence and then exit without searching for more
  823.      occurrences.
  824.  
  825. `!'
  826.      to replace all remaining occurrences without asking again.
  827.  
  828. `^'
  829.      to go back to the position of the previous occurrence (or what
  830.      used to be an occurrence), in case you changed it by mistake.
  831.      This works by popping the mark ring.  Only one `^' in a row is
  832.      meaningful, because only one previous replacement position is kept
  833.      during `query-replace'.
  834.  
  835. `C-r'
  836.      to enter a recursive editing level, in case the occurrence needs
  837.      to be edited rather than just replaced with NEWSTRING.  When you
  838.      are done, exit the recursive editing level with `C-M-c' to proceed
  839.      to the next occurrence.  *Note Recursive Edit::.
  840.  
  841. `C-w'
  842.      to delete the occurrence, and then enter a recursive editing level
  843.      as in `C-r'.  Use the recursive edit to insert text to replace the
  844.      deleted occurrence of STRING.  When done, exit the recursive
  845.      editing level with `C-M-c' to proceed to the next occurrence.
  846.  
  847. `C-l'
  848.      to redisplay the screen.  Then you must type another character to
  849.      specify what to do with this occurrence.
  850.  
  851. `C-h'
  852.      to display a message summarizing these options.  Then you must type
  853.      another character to specify what to do with this occurrence.
  854.  
  855.    Some other characters are aliases for the ones listed above: `y',
  856. `n' and `q' are equivalent to SPC, DEL and RET.
  857.  
  858.    Aside from this, any other character exits the `query-replace', and
  859. is then reread as part of a key sequence.  Thus, if you type `C-k', it
  860. exits the `query-replace' and then kills to end of line.
  861.  
  862.    To restart a `query-replace' once it is exited, use `C-x ESC ESC',
  863. which repeats the `query-replace' because it used the minibuffer to
  864. read its arguments.  *Note C-x ESC ESC: Repetition.
  865.  
  866.    See also *Note Transforming File Names::, for Dired commands to
  867. rename, copy, or link files by replacing regexp matches in file names.
  868.  
  869. 
  870. File: emacs,  Node: Other Repeating Search,  Prev: Replace,  Up: Search
  871.  
  872. Other Search-and-Loop Commands
  873. ==============================
  874.  
  875.    Here are some other commands that find matches for a regular
  876. expression.  They all operate from point to the end of the buffer.
  877.  
  878. `M-x occur RET REGEXP RET'
  879.      Print each line that follows point and contains a match for
  880.      REGEXP.  A numeric argument specifies the number of context lines
  881.      to print before and after each matching line; the default is none.
  882.  
  883.      The buffer `*Occur*' containing the output serves as a menu for
  884.      finding the occurrences in their original context.  Click `Mouse-2'
  885.      on an occurrence listed in `*Occur*', or position point there and
  886.      type `C-c C-c'; this switches to the buffer that was searched and
  887.      moves point to the original of the chosen occurrence.
  888.  
  889. `M-x list-matching-lines'
  890.      Synonym for `M-x occur'.
  891.  
  892. `M-x count-matches RET REGEXP RET'
  893.      Print the number of matches for REGEXP after point.
  894.  
  895. `M-x flush-lines RET REGEXP RET'
  896.      Delete each line that follows point and contains a match for
  897.      REGEXP.
  898.  
  899. `M-x keep-lines RET REGEXP RET'
  900.      Delete each line that follows point and *does not* contain a match
  901.      for REGEXP.
  902.  
  903. 
  904. File: emacs,  Node: Fixit,  Next: Files,  Prev: Search,  Up: Top
  905.  
  906. Commands for Fixing Typos
  907. *************************
  908.  
  909.    In this chapter we describe the commands that are especially useful
  910. for the times when you catch a mistake in your text just after you have
  911. made it, or change your mind while composing text on the fly.
  912.  
  913.    The most fundamental command for correcting erroneous editing is the
  914. undo command, `C-x u' or `C-_'.  This command undoes a single command
  915. (usually), a part of a command (in the case of `query-replace'), or
  916. several consecutive self-inserting characters.  Consecutive repetitions
  917. of `C-_' or `C-x u' undo earlier and earlier changes, back to the limit
  918. of the undo information available.  *Note Undo::, for for more
  919. information.
  920.  
  921. * Menu:
  922.  
  923. * Kill Errors:: Commands to kill a batch of recently entered text.
  924. * Transpose::   Exchanging two characters, words, lines, lists...
  925. * Fixing Case:: Correcting case of last word entered.
  926. * Spelling::    Apply spelling checker to a word, or a whole file.
  927.  
  928. 
  929. File: emacs,  Node: Kill Errors,  Next: Transpose,  Up: Fixit
  930.  
  931. Killing Your Mistakes
  932. =====================
  933.  
  934. `DEL'
  935.      Delete last character (`delete-backward-char').
  936.  
  937. `M-DEL'
  938.      Kill last word (`backward-kill-word').
  939.  
  940. `C-x DEL'
  941.      Kill to beginning of sentence (`backward-kill-sentence').
  942.  
  943.    The DEL character (`delete-backward-char') is the most important
  944. correction command.  It deletes the character before point.  When DEL
  945. follows a self-inserting character command, you can think of it as
  946. canceling that command.  However, avoid the mistake of thinking of DEL
  947. as a general way to cancel a command!
  948.  
  949.    When your mistake is longer than a couple of characters, it might be
  950. more convenient to use `M-DEL' or `C-x DEL'.  `M-DEL' kills back to the
  951. start of the last word, and `C-x DEL' kills back to the start of the
  952. last sentence.  `C-x DEL' is particularly useful when you change your
  953. mind about the phrasing of the text you are writing.  `M-DEL' and `C-x
  954. DEL' save the killed text for `C-y' and `M-y' to retrieve.  *Note
  955. Yanking::.
  956.  
  957.    `M-DEL' is often useful even when you have typed only a few
  958. characters wrong, if you know you are confused in your typing and aren't
  959. sure exactly what you typed.  At such a time, you cannot correct with
  960. DEL except by looking at the screen to see what you did.  Often it
  961. requires less thought to kill the whole word and start again.
  962.  
  963. 
  964. File: emacs,  Node: Transpose,  Next: Fixing Case,  Prev: Kill Errors,  Up: Fixit
  965.  
  966. Transposing Text
  967. ================
  968.  
  969. `C-t'
  970.      Transpose two characters (`transpose-chars').
  971.  
  972. `M-t'
  973.      Transpose two words (`transpose-words').
  974.  
  975. `C-M-t'
  976.      Transpose two balanced expressions (`transpose-sexps').
  977.  
  978. `C-x C-t'
  979.      Transpose two lines (`transpose-lines').
  980.  
  981.    The common error of transposing two characters can be fixed, when
  982. they are adjacent, with the `C-t' command (`transpose-chars').
  983. Normally, `C-t' transposes the two characters on either side of point.
  984. When given at the end of a line, rather than transposing the last
  985. character of the line with the newline, which would be useless, `C-t'
  986. transposes the last two characters on the line.  So, if you catch your
  987. transposition error right away, you can fix it with just a `C-t'.  If
  988. you don't catch it so fast, you must move the cursor back to between
  989. the two transposed characters.  If you transposed a space with the last
  990. character of the word before it, the word motion commands are a good
  991. way of getting there.  Otherwise, a reverse search (`C-r') is often the
  992. best way.  *Note Search::.
  993.  
  994.    `M-t' (`transpose-words') transposes the word before point with the
  995. word after point.  It moves point forward over a word, dragging the
  996. word preceding or containing point forward as well.  The punctuation
  997. characters between the words do not move.  For example, `FOO, BAR'
  998. transposes into `BAR, FOO' rather than `BAR FOO,'.
  999.  
  1000.    `C-M-t' (`transpose-sexps') is a similar command for transposing two
  1001. expressions (*note Lists::.), and `C-x C-t' (`transpose-lines')
  1002. exchanges lines.  They work like `M-t' except in determining the
  1003. division of the text into syntactic units.
  1004.  
  1005.    A numeric argument to a transpose command serves as a repeat count:
  1006. it tells the transpose command to move the character (word, sexp, line)
  1007. before or containing point across several other characters (words,
  1008. sexps, lines).  For example, `C-u 3 C-t' moves the character before
  1009. point forward across three other characters.  It would change
  1010. `f-!-oobar' into `oobf-!-ar'.  This is equivalent to repeating `C-t'
  1011. three times.  `C-u - 4 M-t' moves the word before point backward across
  1012. four words.  `C-u - C-M-t' would cancel the effect of plain `C-M-t'.
  1013.  
  1014.    A numeric argument of zero is assigned a special meaning (because
  1015. otherwise a command with a repeat count of zero would do nothing): to
  1016. transpose the character (word, sexp, line) ending after point with the
  1017. one ending after the mark.
  1018.  
  1019. 
  1020. File: emacs,  Node: Fixing Case,  Next: Spelling,  Prev: Transpose,  Up: Fixit
  1021.  
  1022. Case Conversion
  1023. ===============
  1024.  
  1025. `M-- M-l'
  1026.      Convert last word to lower case.  Note `Meta--' is Meta-minus.
  1027.  
  1028. `M-- M-u'
  1029.      Convert last word to all upper case.
  1030.  
  1031. `M-- M-c'
  1032.      Convert last word to lower case with capital initial.
  1033.  
  1034.    A very common error is to type words in the wrong case.  Because of
  1035. this, the word case-conversion commands `M-l', `M-u' and `M-c' have a
  1036. special feature when used with a negative argument: they do not move the
  1037. cursor.  As soon as you see you have mistyped the last word, you can
  1038. simply case-convert it and go on typing.  *Note Case::.
  1039.  
  1040.